package edu.ucsd.ccdb.generalDataType;

public enum BytesMeasurement {
	
	KILOBYTES (1024),
	MEGABYTES (1048576),
	GIGABYTES (1073741824);
	
	private long lengthInBytes ;
	
	BytesMeasurement( long length) {
		this.lengthInBytes = length;		
	}
	
	public long getLength () {
		return lengthInBytes;
	}
	
	public static String getReadableLength (long length) {
		if (length >= KILOBYTES.getLength() && length < MEGABYTES.getLength() ) 
			return (long) (length / KILOBYTES.getLength() )  + " KB" ; 
		
		if (length >= MEGABYTES.getLength() && length < GIGABYTES.getLength() ) 
			return (long) (length / MEGABYTES.getLength()) + " MB"  ;
		
		if (length >= GIGABYTES.getLength() )
			return (long) (length / GIGABYTES.getLength()  ) + " GB";
		
		// too large or too little
		return length + " bytes";
	}
	
}
